let api = [];
const apiDocListSize = 1
api.push({
    name: 'default',
    order: '1',
    list: []
})
api[0].list.push({
    alias: '7111afde44bf5d792a5bad72fa6ab6f3',
    order: '1',
    link: '通用接口',
    desc: '通用接口',
    list: []
})
api[0].list[0].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/common/device/simple',
    desc: '获取全部设备列表（简要信息）',
});
api[0].list.push({
    alias: '88dfb6aaaf1d5b16860640d6e6e2cbd6',
    order: '2',
    link: '控制模块',
    desc: '控制模块',
    list: []
})
api[0].list[1].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/device',
    desc: '控制设备数据',
});
api[0].list[1].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/device/new',
    desc: '控制设备数据',
});
api[0].list[1].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/device/info',
    desc: '设备数据',
});
api[0].list[1].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/strategy/list',
    desc: '策略列表',
});
api[0].list[1].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/strategy/enable',
    desc: '启停策略',
});
api[0].list[1].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/strategy/info',
    desc: '策略详情',
});
api[0].list[1].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/ctr/strategy/setDevice',
    desc: '设置策略应用设备',
});
api[0].list.push({
    alias: '58e795bc6bd7e9bf2b948567d4d9caba',
    order: '3',
    link: '首页相关',
    desc: '首页相关',
    list: []
})
api[0].list[2].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/pv/data',
    desc: '光伏发电数据',
});
api[0].list[2].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/energy/data',
    desc: '能源情况',
});
api[0].list[2].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/device/info',
    desc: '设备情况',
});
api[0].list[2].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/strategy/cur',
    desc: '当前策略',
});
api[0].list[2].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/map',
    desc: '能源流向图数据',
});
api[0].list[2].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/home/reduce',
    desc: '节能减排数据',
});
api[0].list.push({
    alias: 'bd29aa5fd149b052040c7cf0f7bf9ba3',
    order: '4',
    link: '储能（华为）',
    desc: '储能（华为）',
    list: []
})
api[0].list[3].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/hw/cn/list',
    desc: '获取用户设备列表',
});
api[0].list[3].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/hw/cn/info',
    desc: '获取当前设备数据',
});
api[0].list[3].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/hw/cn/mode/set',
    desc: '储能箱充放电模式',
});
api[0].list.push({
    alias: '02fe8f7b00e283a7a29dc53a544200a6',
    order: '5',
    link: '逆变器（华为）',
    desc: '逆变器（华为）',
    list: []
})
api[0].list[4].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/hw/inverter/list',
    desc: '获取用户设备列表',
});
api[0].list[4].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/hw/inverter/info',
    desc: '获取当前设备数据',
});
api[0].list.push({
    alias: '2db29075135cb44040cb814ec8ef5949',
    order: '6',
    link: '登录模块',
    desc: '登录模块',
    list: []
})
api[0].list[5].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/login/login',
    desc: '登录',
});
api[0].list.push({
    alias: '7b28cb58c3400a93c8a968c90f20980c',
    order: '7',
    link: '监测中心',
    desc: '监测中心',
    list: []
})
api[0].list[6].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/cur',
    desc: '当前数据',
});
api[0].list[6].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/elect/data',
    desc: '电量趋势分析',
});
api[0].list[6].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/inverter/power',
    desc: '逆变器实时功率',
});
api[0].list[6].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/inverter/list',
    desc: '逆变器列表',
});
api[0].list[6].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/inverter/info',
    desc: '逆变器数据',
});
api[0].list[6].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/param/list',
    desc: '查询设备参数列表',
});
api[0].list[6].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/storage/list',
    desc: '储能柜列表',
});
api[0].list[6].list.push({
    order: '8',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/storage/info',
    desc: '储能柜数据',
});
api[0].list[6].list.push({
    order: '9',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/monitor/pv/param/data',
    desc: '查询光伏参数数据(最大值)',
});
api[0].list.push({
    alias: '05c978753b9927e9f2da4f5ca9d3f4a1',
    order: '8',
    link: '个人中心',
    desc: '个人中心',
    list: []
})
api[0].list[7].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/personal/user/info',
    desc: '用户信息',
});
api[0].list[7].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/personal/editPwd',
    desc: '修改密码',
});
api[0].list[7].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/personal/signOut',
    desc: '注销登录',
});
api[0].list.push({
    alias: '5b78868df914bd11fd755b6dc7747e1a',
    order: '9',
    link: '视频监控',
    desc: '视频监控',
    list: []
})
api[0].list[8].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/spjk/list',
    desc: '获取用户设备列表',
});
api[0].list[8].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/spjk/info',
    desc: '获取当前设备数据',
});
api[0].list.push({
    alias: '8e88d2de86e9da8978f98b259254e280',
    order: '10',
    link: '预警相关',
    desc: '预警相关',
    list: []
})
api[0].list[9].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/warn/ov',
    desc: '预警总览',
});
api[0].list[9].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/warn/list',
    desc: '预警列表',
});
api[0].list[9].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/warn/read',
    desc: '预警(已读处理)',
});
api[0].list.push({
    alias: '67489060dcc4cf648e4c01202ae2a624',
    order: '11',
    link: '分体空调(亚禾)',
    desc: '分体空调(亚禾)',
    list: []
})
api[0].list[10].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/list',
    desc: '获取用户设备列表',
});
api[0].list[10].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/info',
    desc: '获取当前设备数据',
});
api[0].list[10].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setAcd',
    desc: '操作空调（手动实时）',
});
api[0].list[10].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setAcdPolicy',
    desc: '设置空调策略方案',
});
api[0].list[10].list.push({
    order: '5',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/delAcdPolicy',
    desc: '移除空调上的策略方案',
});
api[0].list[10].list.push({
    order: '6',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setAcdPolicySwitch',
    desc: '设置空调的策略开关',
});
api[0].list[10].list.push({
    order: '7',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/refreshAcdTime',
    desc: '空调校对时间',
});
api[0].list[10].list.push({
    order: '8',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setAcdPolicyData',
    desc: '设置分体空调策略初始参数',
});
api[0].list[10].list.push({
    order: '9',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setAcdPowerSwitch',
    desc: '设置分体空调继电器开关',
});
api[0].list[10].list.push({
    order: '10',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/air/setBeeWarn',
    desc: '设置蜂鸣预警器开关',
});
api[0].list.push({
    alias: 'a15bc8f8e7fa3a1db56a379e40ae8f2b',
    order: '12',
    link: '风机盘管(亚禾)',
    desc: '风机盘管(亚禾)',
    list: []
})
api[0].list[11].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/fc/list',
    desc: '获取用户设备列表',
});
api[0].list[11].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/fc/info',
    desc: '获取当前设备数据',
});
api[0].list[11].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/fc/set',
    desc: '即时控制',
});
api[0].list.push({
    alias: 'ed0ab6ec368c577d83ca2f0b8701d046',
    order: '13',
    link: '灯控(亚禾)',
    desc: '灯控(亚禾)',
    list: []
})
api[0].list[12].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/light/list',
    desc: '获取用户设备列表',
});
api[0].list[12].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/light/info',
    desc: '获取当前设备数据',
});
api[0].list[12].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/light/set',
    desc: '即时控制',
});
api[0].list.push({
    alias: 'b05613942e1dae57b607c653d941f4a3',
    order: '14',
    link: '智能插座(亚禾)',
    desc: '智能插座(亚禾)',
    list: []
})
api[0].list[13].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/sp/list',
    desc: '获取用户设备列表',
});
api[0].list[13].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/sp/info',
    desc: '获取当前设备数据',
});
api[0].list[13].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/sp/set',
    desc: '即时控制',
});
api[0].list.push({
    alias: '20ea7c1f06a1de63d68b73919e692e4c',
    order: '15',
    link: '多联机空调(亚禾)',
    desc: '多联机空调(亚禾)',
    list: []
})
api[0].list[14].list.push({
    order: '1',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/vrv/list',
    desc: '获取用户设备列表',
});
api[0].list[14].list.push({
    order: '2',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/vrv/info',
    desc: '获取当前设备数据',
});
api[0].list[14].list.push({
    order: '3',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/vrv/info/sub',
    desc: '获取子机数据',
});
api[0].list[14].list.push({
    order: '4',
    deprecated: 'false',
    url: 'http://n.seccn.vip:61014/api/yh/vrv/sub/set',
    desc: '即时控制内机',
});
api[0].list.push({
    alias: 'error',
    order: '16',
    link: 'error_code_list',
    desc: '错误码列表',
    list: []
})
document.onkeydown = keyDownSearch;
function keyDownSearch(e) {
    const theEvent = e;
    const code = theEvent.keyCode || theEvent.which || theEvent.charCode;
    if (code == 13) {
        const search = document.getElementById('search');
        const searchValue = search.value.toLocaleLowerCase();

        let searchGroup = [];
        for (let i = 0; i < api.length; i++) {

            let apiGroup = api[i];

            let searchArr = [];
            for (let i = 0; i < apiGroup.list.length; i++) {
                let apiData = apiGroup.list[i];
                const desc = apiData.desc;
                if (desc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                    searchArr.push({
                        order: apiData.order,
                        desc: apiData.desc,
                        link: apiData.link,
                        list: apiData.list
                    });
                } else {
                    let methodList = apiData.list || [];
                    let methodListTemp = [];
                    for (let j = 0; j < methodList.length; j++) {
                        const methodData = methodList[j];
                        const methodDesc = methodData.desc;
                        if (methodDesc.toLocaleLowerCase().indexOf(searchValue) > -1) {
                            methodListTemp.push(methodData);
                            break;
                        }
                    }
                    if (methodListTemp.length > 0) {
                        const data = {
                            order: apiData.order,
                            desc: apiData.desc,
                            link: apiData.link,
                            list: methodListTemp
                        };
                        searchArr.push(data);
                    }
                }
            }
            if (apiGroup.name.toLocaleLowerCase().indexOf(searchValue) > -1) {
                searchGroup.push({
                    name: apiGroup.name,
                    order: apiGroup.order,
                    list: searchArr
                });
                continue;
            }
            if (searchArr.length === 0) {
                continue;
            }
            searchGroup.push({
                name: apiGroup.name,
                order: apiGroup.order,
                list: searchArr
            });
        }
        let html;
        if (searchValue == '') {
            const liClass = "";
            const display = "display: none";
            html = buildAccordion(api,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        } else {
            const liClass = "open";
            const display = "display: block";
            html = buildAccordion(searchGroup,liClass,display);
            document.getElementById('accordion').innerHTML = html;
        }
        const Accordion = function (el, multiple) {
            this.el = el || {};
            this.multiple = multiple || false;
            const links = this.el.find('.dd');
            links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown);
        };
        Accordion.prototype.dropdown = function (e) {
            const $el = e.data.el;
            $this = $(this), $next = $this.next();
            $next.slideToggle();
            $this.parent().toggleClass('open');
            if (!e.data.multiple) {
                $el.find('.submenu').not($next).slideUp("20").parent().removeClass('open');
            }
        };
        new Accordion($('#accordion'), false);
    }
}

function buildAccordion(apiGroups, liClass, display) {
    let html = "";
    let doc;
    if (apiGroups.length > 0) {
         if (apiDocListSize == 1) {
            let apiData = apiGroups[0].list;
            for (let j = 0; j < apiData.length; j++) {
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiData[j].link + '">' + apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                html += '<ul class="sectlevel2" style="'+display+'">';
                doc = apiData[j].list;
                for (let m = 0; m < doc.length; m++) {
                    let spanString;
                    if (doc[m].deprecated == 'true') {
                        spanString='<span class="line-through">';
                    } else {
                        spanString='<span>';
                    }
                    html += '<li><a href="#_1_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                }
                html += '</ul>';
                html += '</li>';
            }
        } else {
            for (let i = 0; i < apiGroups.length; i++) {
                let apiGroup = apiGroups[i];
                html += '<li class="'+liClass+'">';
                html += '<a class="dd" href="#_' + apiGroup.name + '">' + apiGroup.order + '.&nbsp;' + apiGroup.name + '</a>';
                html += '<ul class="sectlevel1">';

                let apiData = apiGroup.list;
                for (let j = 0; j < apiData.length; j++) {
                    html += '<li class="'+liClass+'">';
                    html += '<a class="dd" href="#_'+apiGroup.order+'_'+ apiData[j].order + '_'+ apiData[j].link + '">' +apiGroup.order+'.'+ apiData[j].order + '.&nbsp;' + apiData[j].desc + '</a>';
                    html += '<ul class="sectlevel2" style="'+display+'">';
                    doc = apiData[j].list;
                    for (let m = 0; m < doc.length; m++) {
                       let spanString;
                       if (doc[m].deprecated == 'true') {
                           spanString='<span class="line-through">';
                       } else {
                           spanString='<span>';
                       }
                       html += '<li><a href="#_'+apiGroup.order+'_' + apiData[j].order + '_' + doc[m].order + '_' + doc[m].desc + '">'+apiGroup.order+'.' + apiData[j].order + '.' + doc[m].order + '.&nbsp;' + spanString + doc[m].desc + '<span></a> </li>';
                   }
                    html += '</ul>';
                    html += '</li>';
                }

                html += '</ul>';
                html += '</li>';
            }
        }
    }
    return html;
}